package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.Mapper.IMovieMapper;
import com.project.bean.MovieBean;
import com.project.service.IMovieService;
import org.springframework.beans.factory.annotation.Autowired;

public class MovieServiceImpl implements IMovieService {
    @Autowired
    private IMovieMapper mapper;

    @Override
    public IPage<MovieBean> findByItem(Integer pageNO, String name, String cinemaName, String time, Integer rowNum) {
        QueryWrapper<MovieBean> qw = new QueryWrapper<>();
        qw.eq("m_status", "未售出");
        if (name != null && name.length() != 0) {
            qw.like("m_name", name);
        }
        if (cinemaName != null && cinemaName.length() != 0) {
            qw.like("m_cinemaName", cinemaName);
        }
        if (time != null && time.length() != 0) {
            qw.like("m_time", time);
        }
        if (rowNum != null) {
            qw.like("m_rowNum", rowNum);
        }
        return mapper.selectPage(new Page<>(pageNO, 3), qw);
    }

    @Override
    public void buyMovie(MovieBean movie) {
        movie.setStatus("已售");
        mapper.updateById(movie);
    }

    @Override
    public MovieBean findById(Integer movieId) {
        return mapper.selectById(movieId);
    }


}
